const fs = require('fs')
const requestPromise = require('request-promise-native')

let content = fs.readFileSync('/home/ofbiz/t.txt', 'utf-8')
let ipArr = content.split('\n')
console.log('ipArr', ipArr)

function jQuery110207587719449261236_1516259585380(res) {
	return res.data[0]
}

// let ip_loc = fs.openSync('/home/ofbiz/ip_loc.txt')

let parseIp = async function() {
	let str = ''
	console.log('ipArr.length', ipArr.length)
	for (let i = 0; i < 1; i++) {
		let ip = ipArr[i]
		if (!ip)
			continue;
		console.log('ip', ip)
		let result = await requestPromise({
			url: `https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=${ip}&co=&resource_id=6006&t=1516259626032&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=baidu&cb=jQuery110207587719449261236_1516259585380&_=1516259585386`,
		})
		console.log('result', result)
		result = eval(result)
		// fs.writeSync(ip_loc)
		str += `${ip}\t\t${result.location}\n\r`
	}
	console.log(str)
	fs.writeFileSync('./ip_loc.txt', str)
}

parseIp()